package titt.head.request;

import titt.head.request.RequestHead;
import titt.head.util.AbstractRequest;

public class BrowserRequestHead extends AbstractRequest {

	public static final String 	MOZILLA_BROWSER = "Mozilla",
								LINUX_OS = "Linux",
								IPHONE_OS = "iPhone OS",
								UNKNOWN = "",
								UNKNOWN_BROWSER = "";

	public BrowserRequestHead(RequestHead req) {
		super.h = req;
	}
	
	public String getBrowser() {
		if(getHeader("User-Agent") == null)
			return UNKNOWN_BROWSER;

		String ua = getHeader("User-Agent").getValue();
		
		if(ua == null) return UNKNOWN_BROWSER;
				
		if(ua.startsWith(MOZILLA_BROWSER)) return MOZILLA_BROWSER;
		
		return UNKNOWN_BROWSER;
	}
	
	public String getOperatingSystem() {
		if(getHeader("User-Agent") == null)
			return UNKNOWN;
		
		String ua = getHeader("User-Agent").getValue();
		
		if(ua == null) return UNKNOWN;

		if(ua.indexOf(LINUX_OS) != -1) return LINUX_OS;
		if(ua.indexOf(IPHONE_OS) != -1) return IPHONE_OS;
		
		return UNKNOWN;
	}
	
	public boolean supportsGZip() {
		if(getHeader("Accept-Encoding") == null)
			return false;
		
		return getHeader("Accept-Encoding").getValue().indexOf("gzip") != -1;
	}
	
	public boolean isOS(String os) {
		return getOperatingSystem().equals(os);
	}
	
}
